package com.yc.d0415;

public class 线程属性 {
    public static void main(String[] args) {
        Thread thread = new Thread();
        // id 唯一表示, 系统指定
        final long id = thread.getId();
        // 线程名称, 可以自定义, 系统会默认命名,
        final String name = thread.getName();
        // 线程优先级 : 1~10, 默认5, 值越大优先级越高
        final int priority = thread.getPriority();
        // 守护线程(精灵线程)标志
        final boolean daemon = thread.isDaemon();

        // 静态方法: 获取当前线程对象
        final Thread currentThread = Thread.currentThread();
        System.out.println(currentThread.getId());
        System.out.println(currentThread.getName());

        System.out.println("thread.id=" + thread.getId());
        System.out.println("thread.getName() = " + thread.getName());

        final Thread t1 = new Thread("订单"){
            @Override
            public void run() {
                // 获取当前线程 t1
                final Thread thread1 = Thread.currentThread();
                System.out.println("thread1.getId() = " + thread1.getId());
                System.out.println("thread1.getName() = " + thread1.getName());
            }
        };
        t1.start();

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                System.out.println("下订单");
            }
        });

        Thread t3 = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                System.out.println("扣库存");
            }
        });

        // 在启动线程之前设置优先级, 才有效
        t2.setPriority(1);
        t3.setPriority(10);

        t2.start();
        t3.start();
    }
}
